#include <avr/io.h>
#include <stdio.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#include "serial.h"

#define USART_BAUDRATE 19200
#define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16UL))) - 1) 

volatile char Direction;
void motor(char Direction);

ISR(USART_RXC_vect){
	char confirm;
	Direction = UDR;
	printf("Direction Received.\n");
	_delay_ms(50);
	motor(Direction);
	

}


void forward(){
	PORTA=0b00010101;
	printf("Moving forward\n");
}

void reverse(){
	PORTA=0b00011010;
	printf("Moving backward\n");


}

void right(){
		PORTA=0b00011001;
	printf("Turning right\n");

}

void left(){
	PORTA=0b00010110;
	printf("Turning left\n");	

}

void stop(){
	PORTA=0b11111111;

}

void motor(char Direction){
	switch(Direction){
		case 'F': forward();
			break;
		case 'B': reverse();
			break;
		case 'R': right();
			break;
		case 'L': left();
			break;
		case 'S': stop();
			break;
		default: printf("Invalid Choice.\n");

	}
}
int main(void){
	_delay_ms(50);
	sei();
	init_uart();
	printf("Program Starting.\n");

	DDRA=0xff;


	while(1){
	}

}
